﻿using System;
using Gencode.Common.Errorhandling;

namespace Gencode.Common
{
	public class Util
	{
		public static double RoundDouble(double number, int precision)
		{
			double retVal;
			switch (precision)
			{
				case 0:
					retVal = (double)((int)number);
					break;
				case 1:
					retVal = (double)(((int)(number * 10)) / 10);
					break;
				case 2:
					retVal = (double)(((int)(number * 100)) / 100);
					break;
				case 3:
					retVal = (double)(((int)(number * 1000)) / 1000);
					break;
				case 4:
					retVal = (double)(((int)(number * 10000)) / 10000);
					break;
				default:
					retVal = (double)(((int)(number * 100000)) / 100000);
					break;
			}
			return retVal;
		}

		static IHandler errorHandler;
		public static IHandler ErrorHandler
		{
			get
			{
				if (errorHandler == null)
					errorHandler = new Handler();

				return errorHandler;
			}
			set
			{
				errorHandler = value;
			}
		}

		//public static void LastErrorText{
		//    get{
		//        return ErrorHandler.
	}
}
